package com.dai.common;

import java.util.Objects;

/**
 * @author daijiyong
 */
public class NodeWithRandomNext {
    public Integer value;
    public NodeWithRandomNext next;
    public NodeWithRandomNext random;

    public NodeWithRandomNext() {
    }

    public NodeWithRandomNext(Integer value) {
        this.value = value;
    }

    public NodeWithRandomNext(Integer value, NodeWithRandomNext next) {
        this.value = value;
        this.next = next;
    }

    public NodeWithRandomNext(Integer value, NodeWithRandomNext next, NodeWithRandomNext random) {
        this.value = value;
        this.next = next;
        this.random = random;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        NodeWithRandomNext that = (NodeWithRandomNext) o;
        return Objects.equals(value, that.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value);
    }


    @Override
    public String toString() {
        NodeWithRandomNext temp = this;
        StringBuilder str = new StringBuilder();
        while (temp != null) {

            str.append("(")
                    .append(temp.value)
                    .append(",")
                    .append(Objects.isNull(temp.random) ? "null" : temp.random.value)
                    .append(")")
                    .append("->");
            temp = temp.next;
        }
        str.append("null");
        return str.toString();
    }
}
